﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using FineUI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data;

namespace IHISCETeim.Web.AgentSys.SysMgr
{
    public partial class AddAgentPower : AgentPageBase
    {

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "AgentConfig"; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetConfirmHideReference();

            //初始化
            this.ddlUserId.DataSource = OUserController.GetUserByDepartment("'售后服务部'");
            this.ddlUserId.DataBind();

            List<AgentPowerConfigInfo> list = AgentConfigController.GetAllPowerConfig();
            list.Add(new AgentPowerConfigInfo() { ID = 0, RealName = "空" });
            this.ddlParId.DataSource = list;
            this.ddlParId.DataBind();
            ///
        }
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            AgentPowerConfigInfo obj = new AgentPowerConfigInfo();
            obj.UserId = Convert.ToInt32(this.ddlUserId.SelectedValue);
            obj.ParId = Convert.ToInt32(this.ddlParId.SelectedValue);
            obj.ClaimAmount = Convert.ToDecimal(this.tbxClaimAmount.Text);
            obj.ShowClaimState = this.ddlShowClaimState.SelectedValue;

            if (AgentConfigController.AddPowerConfig(obj)>0)
            {
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                Alert.Show("新增失败！此员工可能已被添加", "提示", MessageBoxIcon.Error);
            }
        }
    }
}